package cn.rokka.rbac.service.impl;


import cn.rokka.rbac.domain.Permission;
import cn.rokka.rbac.mapper.PermissionMapper;
import cn.rokka.rbac.qo.QueryObject;
import cn.rokka.rbac.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;

@Service
@Transactional
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public void delete(Long id) {
        permissionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(Permission record) {
        permissionMapper.insert(record);

    }

    @Override
    public Permission getById(Long id) {
        return permissionMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Permission> listAll() {
        return permissionMapper.selectAll();
    }

    @Override
    public void update(Permission record) {
        permissionMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<Permission> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo<>(permissionMapper.selectForList(qo));
    }

    @Override
    public void batchSave(HashSet<Object> permissions) {
        permissionMapper.batchInsert(permissions);
    }
}
